package GuiClasses;

/**
 * TCSS 360 - Project
 */

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Observer;

import javax.imageio.ImageIO;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import objectClasses.Entry;

/**
 *  An Attendee panel will hold objects that an attendee needs to submit an entry.
 *  
 *  @author Abraham Santini
 */

public class AttendeePanel extends GenericPanel {

	/**
	 * Public constructor that instantiates an AttendeePanel.
	 * @param the_o_er
	 */

	private Entry their_entry;
	private JLabel JLabel_Image = new JLabel();
	private Image their_draft;
	private JTextField Mats = new JTextField();
	private Dimension button_dimension;
	private String file_path;

	public AttendeePanel(Observer the_o_er)  {
		super(the_o_er);
		button_dimension = new Dimension(20, 100);
		
			
		JLabel Draft = new JLabel ("Select a draft to submit:");
		JTextField matz = new JTextField("Tell us about the materials");
		//Abraham Made Changes on Feb 20 at 12:45 pm
//		my_panel.setLayout(new BorderLayout());
//		my_panel.add(Draft, BorderLayout.CENTER);
//		my_panel.add(FileButton, BorderLayout.LINE_END);
//		my_panel.add(submitButton,BorderLayout.PAGE_END);	
		
		JPanel submissionPanel = new JPanel();
		submissionPanel.setLayout(new BoxLayout(submissionPanel, BoxLayout.X_AXIS));
		
		submissionPanel.add(Mats);
		submissionPanel.add(JLabel_Image);
		my_panel.add(submissionPanel);
		my_panel.add(Draft);
		my_panel.add(createButtonPanel());

	}

	public BufferedImage setImage(File fileName){
		BufferedImage image = null;
		try {                
			image = ImageIO.read(fileName);


		} catch (IOException ex) {
			System.out.print("Invalid file!");
		}
		return image;
	}
	
	public Entry getTheirEntry(){
		return their_entry;
	}

	private JPanel createButtonPanel(){
		JPanel temp = new JPanel();
		temp.setLayout(new GridLayout(1,2));
		JButton FileButton = new JButton("Choose your Draft");
		FileButton.setPreferredSize(button_dimension);
		FileButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				JFileChooser chooser = new JFileChooser();
				chooser.showOpenDialog(chooser);
				file_path = chooser.getSelectedFile().getPath();
				their_draft = setImage(chooser.getSelectedFile());
				JLabel_Image.setIcon(new ImageIcon(setImage(chooser.getSelectedFile())));
				my_panel.revalidate();

			}

		});
		temp.add(FileButton);
		
		JButton submitButton = new JButton("Submit Entry");	
		submitButton.setPreferredSize(button_dimension);
		submitButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				their_entry = new Entry(Mats.getText(), their_draft, file_path);
				System.out.println("Got it");
			}

		});
		temp.add(submitButton);
		return temp;
	}


}

